/**
 * 
 */
package com.dopeydev.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * @author marcomartini
 * 
 */
public class PersonalBasesBroadcast extends BroadcastReceiver {

	public interface Action {

		public final static String ADD_BASE = "eu.bstech.action.base_added";
		public final static String REMOVE_BASE = "eu.bstech.action.base_remove";
		public final static String TOGGLE_BASES_OPTIONS = "eu.bstech.action.toggle_bases_options";

		public final static String EDIT_BASE_CENTER = "eu.bstech.action.edit_base_center";
		public final static String EDIT_BASE_RADIUS = "eu.bstech.aciton.edit_base_radius";

		public final static String ENTERED_LOCATION = "eu.bstech.action.entered_location";
		public final static String EXIT_LOCATION = "eu.bstech.action.exit_location";
		public final static String DWELL_LOCATION = "eu.bstech.action.dwell_location";
	}

	public interface Extra {

		public final static String TOGGLE_VALUE = "eu.bstech.extra.base_toggle_value";
		public static final String LATITUDE = "eu.bstech.extras.base_latitude";
		public static final String LONGITUDE = "eu.bstech.extras.base_longitude";
		public static final String ADDRESS_NAME = "eu.bstech.extres.base_address";
		public static final String BASE_RADIUS = "eu.bstech.extres.base_radius";
		public static final String BASE_ID = "eu.bstech.extres.base_id";
		public static final String GEOFENCE_ID = "eu.bstech.extres.geofence_id";

	}

	@Override
	public void onReceive(Context context, Intent intent) {

		String action = intent.getAction();
		if (action.equals(Action.ADD_BASE)) {
			double latitude = intent.getDoubleExtra(Extra.LATITUDE, 0);
			double longitude = intent.getDoubleExtra(Extra.LONGITUDE, 0);
			Integer baseRadius = intent.getIntExtra(Extra.BASE_RADIUS, 200);
			String addressName;
			if (null != intent.getStringExtra(Extra.ADDRESS_NAME)) {
				addressName = intent.getStringExtra(Extra.ADDRESS_NAME);
			} else {
				addressName = "Loading address....";
			}
			addBase(latitude, longitude, baseRadius, addressName);

		} else if (action.equals(Action.TOGGLE_BASES_OPTIONS)) {
			boolean value = intent.getBooleanExtra(Extra.TOGGLE_VALUE, false);
			long geofenceId = intent.getLongExtra(Extra.GEOFENCE_ID, 0);
			toggleBasesMenu(value, geofenceId);
		} else if (action.equals(Action.REMOVE_BASE)) {
			long geofenceId = intent.getLongExtra(Extra.GEOFENCE_ID, 0);
			removeBase(geofenceId);
		} else if (action.equals(Action.ENTERED_LOCATION)) {
			enteredLocation();
		} else if (action.equals(Action.EXIT_LOCATION)) {
			exitLocation();
		} else if (action.equals(Action.DWELL_LOCATION)) {
			dwellLocation();
		} else if (action.equals(Action.EDIT_BASE_CENTER)) {

			double latitude = intent.getDoubleExtra(Extra.LATITUDE, 0);
			double longitude = intent.getDoubleExtra(Extra.LONGITUDE, 0);
			long geofenceId = intent.getLongExtra(Extra.GEOFENCE_ID, 0);
			editBaseCenter(geofenceId, latitude, longitude);

		} else if (action.equals(Action.EDIT_BASE_RADIUS)) {
			double radius = intent.getDoubleExtra(Extra.BASE_RADIUS, 100);
			long geofenceId = intent.getLongExtra(Extra.GEOFENCE_ID, 0);
			editBaseRadius(geofenceId, radius);
		}
	}

	public void editBaseCenter(long geofenceId, double latitude, double longitude) {

	}

	public void editBaseRadius(long geofenceId, double radius) {

	}

	public void exitLocation() {

	}

	public void dwellLocation() {

	}

	public void enteredLocation() {

	}

	public void removeBase(long baseId) {

	}

	public void addBase(double latitude, double longitude, Integer baseRadius, String address) {

	}

	public void toggleBasesMenu(boolean value, long baseId) {

	}
}
